import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  //主页
  {
    path: '/home',
    name: 'Layout',
    component: () => import("../views/layout/index.vue"),
    redirect:'/home/welcome',
    children:[
      //进入主页后，自动跳转到欢迎页
      {
        path:'welcome',
        name:'Welcome',
        component: () => import('../views/home/welcome/index.vue')
      },
      {
        path: 'admin',
        name: 'admin',
        component: () => import('../views/home/admin/index.vue')
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('../views/home/user/index.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/test',
    name: 'Test',
    component: () => import('../views/test/index.vue')
  },
  //若匹配不到资源，则回到主页
  {
    path: "*", 
    name:"error",
    component: () => import('../views/error/index.vue')
  }
]

const router = new VueRouter({
  //mode:'history',  //hash模式（默认）：url里有#号；history模式：url里没有#号；
  routes:routes
})


export default router;
